package com.example.foobar.dao.service.impl;

import com.example.foobar.entity.DyVideo;
import com.example.foobar.mapper.DyVideoMapper;
import com.example.foobar.dao.service.DyVideoDaoService;
import com.example.foobar.param.DyVideoPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.foobar.vo.DyVideoQueryVo;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 抖音视频内容 服务实现类
 *
 * @author 郑英奔
 * @since 2021-07-23
 */
@Slf4j
@Service
public class DyVideoDaoServiceImpl extends BaseServiceImpl<DyVideoMapper, DyVideo> implements DyVideoDaoService {

    @Autowired
    private DyVideoMapper dyVideoMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveDyVideo(DyVideo dyVideo)  {
        return super.save(dyVideo);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateDyVideo(DyVideo dyVideo)  {
        return super.updateById(dyVideo);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteDyVideo(Long id)  {
        return super.removeById(id);
    }

    @Override
    public Paging<DyVideoQueryVo> getDyVideoPageList(DyVideoPageParam dyVideoPageParam)  {
        Page<DyVideoQueryVo> page = new PageInfo<>(dyVideoPageParam, OrderItem.desc(getLambdaColumn(DyVideo::getId)));
        IPage<DyVideoQueryVo> dyVideoPageList = dyVideoMapper.getDyVideoPageList(page, dyVideoPageParam);
        return new Paging(dyVideoPageList);
    }
}
